(function(){var c=$telerik.$;
var e=Telerik.Web.UI;
var d=e.Scheduler;
var h=e.RadScheduler.prototype;
var f=e.SchedulerAppointment.prototype;
function a(){if(!this._isSchedulerContentRendered()){return;
}this._appLoadContextMenuCallback=Function.createDelegate(this,this._appLoadContextMenus);
Sys.Application.add_load(this._appLoadContextMenuCallback);
this.add_timeSlotContextMenu(g);
this.add_appointmentContextMenu(b);
}function i(){if(!this._isSchedulerContentRendered()){return;
}this.remove_timeSlotContextMenu(g);
this.remove_appointmentContextMenu(b);
this._removeAppointmentContextMenuHandlers();
this._removeTimeSlotContextMenuHandlers();
}function g(j,k){j._showTimeSlotContextMenu(k.get_domEvent(),k.get_targetSlot());
}function b(j,k){j._contextMenuAppointment=k.get_appointment();
k.get_appointment().showContextMenu(k.get_domEvent());
}e.RadScheduler._plugins.push({onInitialize:a,onDispose:i});
d.ContextMenuCommands={Edit:"CommandEdit",Delete:"CommandDelete",AddApt:"CommandAddAppointment",AddAptRecurring:"CommandAddRecurringAppointment",ShowFullTime:"CommandShow24Hours",GoToToday:"CommandGoToToday"};
h._appLoadContextMenus=function(){Sys.Application.remove_load(this._appLoadContextMenuCallback);
this._addAppointmentContextMenuHandlers();
this._addTimeSlotContextMenuHandlers();
};
h._addTimeSlotContextMenuHandlers=function(){this._timeSlotContextMenuHandlersAdded=true;
this._timeSlotContextMenuItemClickingDelegate=Function.createDelegate(this,this._timeSlotContextMenuItemClickingHandler);
this._timeSlotContextMenuItemClickedDelegate=Function.createDelegate(this,this._timeSlotContextMenuItemClickedHandler);
var k=this.get_timeSlotContextMenus();
for(var j=0;
j<k.length;
j++){var l=k[j];
if(l){l.add_itemClicking(this._timeSlotContextMenuItemClickingDelegate);
l.add_itemClicked(this._timeSlotContextMenuItemClickedDelegate);
}}};
h._timeSlotContextMenuItemClickingHandler=function(j,l){var n=l.get_item();
var k=n.get_value();
var o=c.raiseCancellableControlEvent(this,"timeSlotContextMenuItemClicking",{slot:this._contextMenuTimeSlot,item:n});
l.set_cancel(o);
if(o){return;
}if(this.get_shouldPostbackOnTimeSlotContextMenuItemClick()&&!this._renderingManager){this._handleServerSideTimeSlotContextMenuItemClick(n);
}else{var m=this._getTimeSlotMenuItemClickHandlers()[k];
if(m){m();
}}};
h._getTimeSlotMenuItemClickHandlers=function(){var j=this;
if(!this._timeSlotClickHandlers){this._timeSlotClickHandlers={};
this._timeSlotClickHandlers[d.ContextMenuCommands.AddApt]=function(){j.showInlineInsertForm(j._contextMenuTimeSlot);
};
this._timeSlotClickHandlers[d.ContextMenuCommands.AddAptRecurring]=function(){var k=j._createAppointmentFromTimeSlot(j._contextMenuTimeSlot);
if(j._renderingManager){k.set_recurrenceState(e.RecurrenceState.Master);
k.set_recurrenceRule(j._createDefaultRecurrenceRule(k));
}j._showAdvancedInsertForm(k,true,j._contextMenuTimeSlot);
};
this._timeSlotClickHandlers[d.ContextMenuCommands.ShowFullTime]=function(){if(j._renderingManager){j.set_showFullTime(!j.get_showFullTime());
}else{j.postback({Command:"SwitchFullTime"});
}};
this._timeSlotClickHandlers[d.ContextMenuCommands.GoToToday]=function(){var k={stopPropagation:function(){},preventDefault:function(){}};
j._onTodayClick(k);
};
}return this._timeSlotClickHandlers;
};
h._createDefaultRecurrenceRule=function(k){var m=[e.RecurrenceDay.Sunday,e.RecurrenceDay.Monday,e.RecurrenceDay.Tuesday,e.RecurrenceDay.Wednesday,e.RecurrenceDay.Thursday,e.RecurrenceDay.Friday,e.RecurrenceDay.Saturday];
var l=new e.RecurrencePattern();
l.set_frequency(e.RecurrenceFrequency.Weekly);
l.set_interval(1);
l.set_daysOfWeekMask(m[k.get_start().getDay()]);
var j=new e.RecurrenceRange();
j.set_start(k.get_start());
j.set_eventDuration(k.get_duration());
return e.RecurrenceRule.fromPatternAndRange(l,j).toString();
};
h._handleServerSideTimeSlotContextMenuItemClick=function(k){var m=this._contextMenuTimeSlot.get_domElement().offsetWidth;
var l=this._contextMenuTimeSlot.get_domElement().offsetHeight;
var j={command:"ContextMenuTimeSlotCommand",contextMenuCommandName:k.get_value(),contextMenuID:k.get_menu().get_id(),menuItemIndex:k._getHierarchicalIndex(),appointmentID:-1,targetSlotIndex:this._contextMenuTimeSlot.get_index(),slotWidth:m,slotHeight:l};
this.postback(j);
};
h._timeSlotContextMenuItemClickedHandler=function(j,k){var l=k.get_item();
c.raiseControlEvent(this,"timeSlotContextMenuItemClicked",{slot:this._contextMenuTimeSlot,item:l});
};
h._addAppointmentContextMenuHandlers=function(){this._contextMenuHandlersAdded=true;
this._appointmentContextMenuItemClickingDelegate=Function.createDelegate(this,this._appointmentContextMenuItemClickingHandler);
this._appointmentContextMenuItemClickedDelegate=Function.createDelegate(this,this._appointmentContextMenuItemClickedHandler);
var k=this.get_appointmentContextMenus();
for(var j=0;
j<k.length;
j++){var l=k[j];
if(l){l.add_itemClicking(this._appointmentContextMenuItemClickingDelegate);
l.add_itemClicked(this._appointmentContextMenuItemClickedDelegate);
}}};
h._appointmentContextMenuItemClickingHandler=function(j,l){var m=l.get_item();
var k=m.get_value();
var n=c.raiseCancellableControlEvent(this,"appointmentContextMenuItemClicking",{appointment:this._contextMenuAppointment,item:m});
l.set_cancel(n);
if(n){return;
}if(this.get_shouldPostbackOnAppointmentContextMenuItemClick()&&!this._renderingManager){if(k==d.ContextMenuCommands.Edit){this._handleServerSideContextMenuEdit(this._contextMenuAppointment,m);
}else{if(k==d.ContextMenuCommands.Delete){this._handleServerSideContextMenuDelete(this._contextMenuAppointment,m);
}else{this._handleServerSideContextMenuItemClick(this._contextMenuAppointment,m);
}}return;
}if(k==d.ContextMenuCommands.Edit){this.editAppointmentWithConfirmation(this._contextMenuAppointment);
}else{if(k==d.ContextMenuCommands.Delete){this.deleteAppointmentWithConfirmation(this._contextMenuAppointment);
}}};
h._handleServerSideContextMenuItemClick=function(j,l){var k={command:"ContextMenuAppointmentCommand",contextMenuCommandName:l.get_value(),contextMenuID:l.get_menu().get_id(),menuItemIndex:l._getHierarchicalIndex(),appointmentID:j._internalID};
this.postback(k);
};
h._handleServerSideContextMenuEdit=function(j,l){if(!j){return;
}var k={OnConfirm:this._onContextMenuEditDialogCallback,Scheduler:this,Appointment:j,CallbackIsCalledFromDialog:true,ContextMenuID:l.get_menu().get_id(),MenuItemIndex:l._getHierarchicalIndex()};
this._showEditConfirmationDialog(k);
};
h._onContextMenuEditDialogCallback=function(k,j){if(j.CallbackIsCalledFromDialog){var m=new e.SchedulerRecurrenceActionDialogClosedEventArgs(j.Appointment,e.RecurrenceAction.Edit,k);
j.Scheduler.raise_recurrenceActionDialogClosed(m);
}var l={command:"ContextMenuEdit",contextMenuID:j.ContextMenuID,menuItemIndex:j.MenuItemIndex,appointmentID:j.Appointment._internalID,editSeries:k};
j.Scheduler.postback(l);
};
h._handleServerSideContextMenuDelete=function(j,l){if(!j){return;
}var k={OnConfirm:this._onContextMenuDeleteDialogCallback,Scheduler:this,Appointment:j,CallbackIsCalledFromDialog:true,ContextMenuID:l.get_menu().get_id(),MenuItemIndex:l._getHierarchicalIndex()};
this._showDeleteConfirmationDialog(k);
};
h._onContextMenuDeleteDialogCallback=function(k,j){if(j.CallbackIsCalledFromDialog){var m=new e.SchedulerRecurrenceActionDialogClosedEventArgs(j.Appointment,e.RecurrenceAction.Delete,k);
j.Scheduler.raise_recurrenceActionDialogClosed(m);
}var l={command:"ContextMenuDelete",contextMenuID:j.ContextMenuID,menuItemIndex:j.MenuItemIndex,appointmentID:j.Appointment._internalID,editSeries:k};
j.Scheduler.postback(l);
};
h._appointmentContextMenuItemClickedHandler=function(j,k){var l=k.get_item();
c.raiseControlEvent(this,"appointmentContextMenuItemClicked",{appointment:this._contextMenuAppointment,item:l});
};
h._removeAppointmentContextMenuHandlers=function(){if(!this._contextMenuHandlersAdded){return;
}var k=this.get_appointmentContextMenus();
for(var j=0;
j<k.length;
j++){var l=k[j];
if(l){l.remove_itemClicking(this._appointmentContextMenuItemClickingDelegate);
l.remove_itemClicked(this._appointmentContextMenuItemClickedDelegate);
}}};
h._removeTimeSlotContextMenuHandlers=function(){if(!this._timeSlotContextMenuHandlersAdded){return;
}var k=this.get_timeSlotContextMenus();
for(var j=0;
j<k.length;
j++){var l=k[j];
if(l){l.remove_itemClicking(this._timeSlotContextMenuItemClickingDelegate);
l.remove_itemClicked(this._timeSlotContextMenuItemClickedDelegate);
}}};
h._showTimeSlotContextMenu=function(k,l){this._contextMenuTimeSlot=l;
var j=this._getTimeSlotContextMenu();
if(j){this._filterTimeSlotContextMenu(j);
j.show(k);
}};
h._filterTimeSlotContextMenu=function(n){if(!this._renderingManager){return;
}var m=this.get_selectedView()==e.SchedulerViewType.TimelineView;
var j=this.get_selectedView()==e.SchedulerViewType.MonthView;
var l=n.findItemByValue(d.ContextMenuCommands.ShowFullTime);
if(l){if(m||j){l.hide();
}else{l.show();
var k=this.get_localization();
l.set_text(this.get_showFullTime()?k.ShowBusinessHours:k.Show24Hours);
}}};
h._getTimeSlotContextMenu=function(){var j=this.get_timeSlotContextMenuIDs();
if(j.length==0){return null;
}return $find(this._resolveContextMenuID(j[0]));
};
h._resolveContextMenuID=function(j){return String.format("{0}_{1}",this.get_id(),j);
};
h.get_appointmentContextMenus=function(){if(!this._appointmentContextMenus){this._appointmentContextMenus=[];
var k=this.get_appointmentContextMenuIDs();
for(var j=0;
j<k.length;
j++){Array.add(this._appointmentContextMenus,$find(this._resolveContextMenuID(k[j])));
}}return this._appointmentContextMenus;
};
h.get_timeSlotContextMenus=function(){if(!this._timeSlotContextMenus){this._timeSlotContextMenus=[];
var k=this.get_timeSlotContextMenuIDs();
for(var j=0;
j<k.length;
j++){Array.add(this._timeSlotContextMenus,$find(this._resolveContextMenuID(k[j])));
}}return this._timeSlotContextMenus;
};
f.showContextMenu=function(k){var j=this.get_contextMenu();
if(j){j.show(k);
}};
f.get_contextMenu=function(){if(!this._contextMenu){var j=this.get_owner();
var l=j.get_appointmentContextMenuIDs();
if(l.length==0){return null;
}var k=this.get_contextMenuID()||l[0];
this._contextMenu=$find(j._resolveContextMenuID(k));
}return this._contextMenu;
};
})();
